<%-- 
    Document   : header
    Created on : Mar 25, 2014, 8:31:38 AM
    Author     : asmaa
--%>
<!DOCTYPE HTML>

<%@ page import="java.io.*,java.util.*,java.sql.*"%>
<%@ page import="javax.servlet.http.*,javax.servlet.*" %>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%@ page isELIgnored ="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>

<sql:setDataSource var="conn" driver="com.mysql.jdbc.Driver"
                                        url="jdbc:mysql://localhost/Shopping"
                                        user="root"  password="asmaaelmasry"/>
 
<html>
    <head>
        <title>The Fooseshoes Website Template | Home :: w3layouts</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <link href='http://fonts.googleapis.com/css?family=Maven+Pro:400,900,700,500' rel='stylesheet' type='text/css'>
        <link href="css/style.css" rel="stylesheet" type="text/css" media="all" />
        <!--- start-mmmenu-script---->
        <script src="js/jquery.min.js" type="text/javascript"></script>
        <link href="css/bootstrap.min.css" rel="stylesheet">
        <link type="text/css" rel="stylesheet" href="css/jquery.mmenu.all.css" />
        <script type="text/javascript" src="js/jquery.mmenu.js"></script>
        
        <!-- start slider -->
        <link href="css/slider.css" rel="stylesheet" type="text/css" media="all" />
        <script type="text/javascript" src="js/jquery.eislideshow.js"></script>
        <script type="text/javascript" src="js/easing.js"></script>
        <script type="text/javascript">
            $(function() {
                $('#ei-slider').eislideshow({
                    animation: 'center',
                    autoplay: true,
                    slideshow_interval: 3000,
                    titlesFactor: 0
                });
            });
        </script>
        <!-- start top_js_button -->
        <script type="text/javascript" src="js/move-top.js"></script>
        <script type="text/javascript">
            jQuery(document).ready(function($) {
                $(".scroll").click(function(event) {
                    event.preventDefault();
                    $('html,body').animate({scrollTop: $(this.hash).offset().top}, 1200);
                });
            });
        </script>
        </script>
        <script type="text/javascript">
        function go_ajax(){    
        
     var xmlhttp = new XMLHttpRequest();
     var check_for=document.getElementById("searchbar").value;
        xmlhttp.open('POST','SearchServlet',true);
        var parameter="check_for="+check_for;
        xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
        xmlhttp.send(parameter);
        xmlhttp.onreadystatechange = function()
                {
                    if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                    {
                        //alert(xmlhttp.responseText);
                        document.getElementById("here").innerHTML = xmlhttp.responseText;
                    }
                };

            
        
        
        
        
        
    }
        </script>
    </head>
    <body>
        <!-- start header -->
        <div class="top_bg">
            <div class="wrap">
                <div class="header">
                    <div class="logo">
                        <a href="index.jsp"><img src="images/logo.png" alt=""/></a>
                    </div>
                    <div class="log_reg">
                        <ul>
                            <c:choose>
                                <c:when test="${empty sessionScope.email}">
                                    <li><a href="signin.jsp">Login</a> </li>
                                    <span class="log"> or </span>
                                    <li><a href="Registration.jsp">Register</a> </li>								   
                                </c:when>
                                <c:otherwise>
                                    <li><a href="profile.jsp?id=${sessionScope.id}">${sessionScope.name}</a></li>                                
                                    <span class="log"> or </span>
                                    <li><a href="LogOut">Log Out</a> </li>
                                </c:otherwise>
                            </c:choose>
                        </ul>
                    </div>	
                    <div class="web_search">
                        <form>
                            <input type="text" id="searchbar" onchange="go_ajax();"/> 
                            <input type="submit" onclick="go_ajax(); return false;" value=" " />
                        </form>
                    </div>						
                    <div class="clear"></div>
                </div>	
            </div>
        </div>
        <!-- start header_btm -->
        <div class="wrap">
            <div class="header_btm">
                <div class="menu">
                    <ul>
                        <li class="active"><a href="index.jsp">Home</a></li>
                        <li><a href="allproducts.jsp">products</a></li>
                            <c:if test="${!empty sessionScope.email && sessionScope.role == 1}">
                                <li><a href="AllProductView.jsp">Control Panel</a></li>
                            </c:if>
                        <div class="clear"></div>
                    </ul>
                </div>
                <div id="smart_nav">
                    <a class="navicon" href="#menu-left"> </a>
                </div>
                
                <div class="header_right">
                    <ul>
                        <!-- <li><a href="#"><i  class="art"></i><span class="color1">30</span></a></li> -->
                        <c:choose>
                            <c:when test="${empty sessionScope.email}">
                                <li><a href="signin.jsp"><i  class="cart"></i><span>0</span></a></li>
                            </c:when>
                            <c:otherwise>
                                <sql:query dataSource="${conn}" var="cart">
                                    SELECT SUM(quantity) As bagCount from Cart where status =0 and userId = ? ;
                                    <sql:param value="${sessionScope.id}" />
                                </sql:query>
                                <li>
                                    <a href="BuyCart">
                                        <i class="cart"></i>
                                        <c:choose>
                                            <c:when test="${cart.rows[0].bagCount == 0 || empty cart.rows[0].bagCount}" >
                                                <span id="cart" >0</span>
                                            </c:when>
                                            <c:otherwise>
                                                <span id="cart" >${cart.rows[0].bagCount}</span>
                                            </c:otherwise>
                                        </c:choose>                                        
                                    </a>
                                </li>
                            </c:otherwise>
                        </c:choose>
                    </ul>
                </div>
                <div class="clear"></div>
            </div>
        </div>